package com.yesep;

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import com.yesep.client.NettyClient;
import com.yesep.netty.NettyServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication(scanBasePackages = "com.yesep.*")
//@ImportResource(locations = {"classpath:dubbo-customer.xml"})
//@EnableDubbo
public class EnvmGatewayApplication implements CommandLineRunner {

    public static void main(String[] args) {
        try {
            SpringApplication.run(EnvmGatewayApplication.class, args);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    @Value("${netty.port}")
    private int port;

    @Value("${netty.host}")
    private String host;

    @Autowired
    private NettyClient nettyClient;

    @Autowired
    private NettyServer nettyServer;

    @Override
    public void run(String... args) throws Exception {
        System.out.println("Netty Server starting ...");
        nettyServer.start(port);
        System.out.println("Netty Client starting ...");
        nettyClient.start(host, port);
    }
}
